<template>
  <el-dialog :visible.sync="popeval" title="用血后评价" :close-on-click-modal="false" :center="true" v-el-drag-dialog width="830px">
          <el-form :inline="true" :model="orderInfo" @submit.native.prevent label-width="auto" ref="form2" style="border:1px solid #ccc">
              <el-card>
                  <div slot="header" class="clearfix">
                      <span>患者信息</span>
                  </div>
                  <div>
                      <div v-html="orderInfo.patInfo" style="padding:5px"></div>
                  </div>
              </el-card>
              <el-card>
                  <div slot="header" class="clearfix">
                      <span>输注记录</span>
                  </div>
                  <div>
                      <div v-html="orderInfo.bagInfo" style="padding:5px 0"></div>
                  </div>
              </el-card>
              <el-card>
                  <div slot="header" class="clearfix">
                      <span>输血指标变化信息</span>
                  </div>
                  <div>
                      <div v-html="orderInfo.itemChangeInfo" style="padding:5px 0"></div>
                  </div>
              </el-card>
              <el-card>
                  <div slot="header" class="clearfix">
                      <span>临床评价信息</span>
                  </div>
                  <div>
                      <div v-html="orderInfo.evalInfo" style="padding:5px 0"></div>
                  </div>
              </el-card>
              <el-card>
                  <div slot="header" class="clearfix">
                      <span>输血科评价</span>
                  </div>
                  <div>
                      <table style="width:100%">
                          <tr>
                              <td style="width:76px">输血是否有效:</td>
                              <td style="width:100px">
                                  <el-select style="width:100%;" v-model="orderInfo.bd_valid" ref="bd_valid">
                                      <el-option value="1" label="有效"></el-option>
                                      <el-option value="2" label="无效"></el-option>
                                  </el-select>
                              </td>
                              <td style="width:64px">无效原因:</td>
                              <td colspan="3">
                                  <el-input type="text" :disabled="orderInfo.bd_valid!='2'"  v-model="orderInfo.bd_notvalid"></el-input>
                              </td>
                          </tr>
                          <tr>
                              <td>输血是否合理:</td>
                              <td>
                                  <el-select style="width:100%;" v-model="orderInfo.bd_rational" ref="bd_rational">
                                      <el-option value="1" label="合理"></el-option>
                                      <el-option value="2" label="部分合理"></el-option>
                                      <el-option value="3" label="不合理"></el-option>
                                  </el-select>
                              </td>
                              <td>不合理原因:</td>
                              <td>
                                  <el-input type="text" :disabled="orderInfo.bd_rational!='2'&&orderInfo.bd_rational!='3'" v-model="orderInfo.bd_notrational"></el-input>
                              </td>
                              <td style="width:64px">不合理成分:</td>
                              <td style="width:150px">
                                  <el-select style="width:100%;" :disabled="orderInfo.bd_rational!='2'" v-model="orderInfo.bd_notrationalcomp" ref="bd_notrationalcomp">
                                      <el-option v-for="compitem in orderInfo.comps" :key="compitem.compno" :value="compitem.compno" :label="compitem.compna"></el-option>
                                  </el-select>
                              </td>
                          </tr>
                      </table>
                  </div>
              </el-card>
              
          </el-form>
          <div style="text-align:right;padding-top:5px">
              <el-button @click="backDoctor()" type="warning">退回临床重新评价</el-button>
              <el-button @click="eval(0)">保存</el-button>
              <el-button @click="eval(1)">提交</el-button>
              <el-button @click="popeval=false">取消</el-button>
          </div>
      </el-dialog>
</template>

<script>
export default {
  name: "NBS514",
  data() {
      return {
          evalUser:'',
          popeval:false,
          orderInfo:{},
          evalid:0,
          msgid:0
      };
  },
  created() {
      //this.openeval(this.msgid,this.evalid);
  },
  mounted() {
      
  },
  watch: {},
  computed: {
  },
  methods: {
      backDoctor(){
          //弹出用户验证框
          this.$rm_Login({
                  type: "请输入退回临床重新评价工号和密码",
                  btn: {
                      confirmBtnText: "确定",
                      cancelBtnText: "取消"
                  }
              })
              .then(res => {
                  if (res.flag == "1") {
                      this.$tool
                          .request({
                              url: "NBS/NBS5/NBS514",
                              method: "post",
                              data: {
                                  action: "backdoctor",
                                  orderid:this.orderInfo.orderid,
                                  userno:res.userid,
                                  msgid:this.orderInfo.msgid,
                                  evalid:this.orderInfo.evalid
                              }
                          })
                          .then(res => {
                              if(res.errcode=='1'){
                                  this.$message.success("退回临床重新评价成功！");
                                  this.$emit('afterEval',0);
                                  //this.refresh();
                                  this.popeval=false;
                              }
                              else{
                                  this.$alert('退回临床重新评价失败：'+res.errmsg+'！', "错误", {
                                      confirmButtonText: "确定"
                                  });
                              }
                          })
                          .catch(err => {
                              this.$message.error("错误:" + err);
                          });
                  } else {
                      //登录失败
                  }
              })
              .catch(err => {
                  this.$message.error("错误:" + err);
              });
      },
      eval(flag){
          //console.log(this.evalUser=='');
          if(this.evalUser=='' && flag==1){
              //弹出用户验证框
              this.$rm_Login({
                      type: "请输入评价医生工号和密码",
                      btn: {
                          confirmBtnText: "确定",
                          cancelBtnText: "取消"
                      }
                  })
                  .then(res => {
                      if (res.flag == "1") {
                          this.evalUser=res.userid;
                          this.$emit('setUser',res.userid,res.username);
                          this.evalOrder(flag);
                      } else {
                          //登录失败
                      }
                  })
                  .catch(err => {
                      //this.$message.error("错误:" + err);
                  });
          }
          else{
              this.evalOrder(flag);
          }
          
      },
      evalOrder(flag){
          var that=this;
          this.$tool
              .request({
                  url: "NBS/NBS5/NBS514",
                  method: "post",
                  data: {
                      action: "eval",
                      flag:flag,
                      userno:that.evalUser,
                      msgid:that.orderInfo.msgid,
                      evalid:that.orderInfo.evalid,
                      bd_valid:that.orderInfo.bd_valid,
                      bd_notvalid:that.orderInfo.bd_notvalid,
                      bd_rational:that.orderInfo.bd_rational,
                      bd_notrational:that.orderInfo.bd_notrational,
                      bd_notrationalcomp:that.orderInfo.bd_notrationalcomp,
                  }
              })
              .then(res => {
                  if(res.errcode=='1'){
                      this.$message.success(flag==0?"保存成功！":"提交成功！");
                      
                      if(flag==1){
                          this.popeval=false;
                          this.$emit('afterEval',1);
                      }
                      
                  }
                  else{
                      this.$alert('保存失败：'+res.errmsg+'！', "错误", {
                          confirmButtonText: "确定"
                      });
                  }
              })
              .catch(err => {
                   this.$message.error("错误:" + err);
              });
          
      },
      openeval(msgid,evalid,userno) {
          this.evalUser=userno;
          var that=this;
          this.$tool
              .request({
                  url: "NBS/NBS5/NBS514",
                  method: "post",
                  data: {
                      action: "getorderinfo",
                      msgid:msgid,
                      evalid:evalid
                  }
              })
              .then(res => {
                  that.orderInfo = res;
                  that.popeval=true;
              })
              .catch(err => {
                  this.$message.error("错误:" + err);
              });
      }
  }
};
</script>
